package common

import "encoding/json"

const SUCCESS = "000000"
const FAIL = "fail"

type Result struct {
	Code string
	Data interface{}
}

func (r *Result) Success(i interface{}) {
	r.Code = SUCCESS
	r.Data = i
}
func (r *Result) Fail(i interface{}) {
	r.Code = FAIL
	r.Data = i
}

func (r *Result) ToByte() []byte {
	bs, err := json.MarshalIndent(r, "", "    ")
	if err != nil {
		return []byte(err.Error())
	}
	return bs
}
